<template>
  <div class="vx-user-overview">
    <p class="theme-title">
      <span>用户概览</span>
    </p>
    <div class="user-chart"></div>
    <div class="product-msg">公司内部用户/外部用户</div>
  </div>
</template>

<script>
import Clay from '@csii/vx-clay/dist/clay-template.js';
import './ui-user-overview';
export default {
  name: 'vx-user-overview',
  props: {
    data: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {};
  },
  watch: {
    data: {
      handler() {
        this.painterAsset();
      },
      deep: true,
    },
  },
  methods: {
    /**
     * @description:创建数据图像,图形绘制跳转
     */
    painterAsset() {
      const that = this;
      window.zl = new Clay({
        el: document.querySelector('.user-chart'),
        template: `
        <ui-user-overview :data="userSummary" c-on:mousemove="doit"></ui-user-overview>
        `,
        data() {
          return {
            userSummary: that.data,
          };
        },
        methods: {
          doit(target) {
            let title;
            let content;
            if (target.subRegion === '0') {
              title = '公司内部用户';
              content = ((target.attr.data.internalUser / (target.attr.data.internalUser + target.attr.data.externalUser)) * 100).toFixed(2) + '%';
            } else if (target.subRegion === '1') {
              title = '外部用户';
              content = ((target.attr.data.externalUser / (target.attr.data.internalUser + target.attr.data.externalUser)) * 100).toFixed(2) + '%';
            }
            this.$setHover({
              title: title,
              x: target.left,
              y: target.top,
              show: true,
              items: [
                {
                  color: 'red',
                  content: content,
                  radius: '5',
                },
              ],
            });
          },
        },
      });
    },
  },
};
</script>

<style lang="scss">
.vx-user-overview {
  flex: 1;
  height: 350px;
  .user-chart {
    margin-left: 240px;
    width: 240px;
    height: 240px;
  }
  .product-msg {
    font-size: 14px;
    margin-left: 280px;
  }
}
</style>
